% students:
% Gilad Darmon ID=046248357
% Shiran Stan-Meleh ID=039067608
function [ res ] = checkConvex( xy )
%this fucntions uses the law of cosines in order to find if the quaderatial
%is a convex.the basic idea is to compute all of the degress and if < 360
%degrees it is not a convex else it is.

a = sqrt( (xy(1,2) - xy(1,1))^2 + (xy(2,2) - xy(2,1))^2 );
b = sqrt( (xy(1,3) - xy(1,2))^2 + (xy(2,3) - xy(2,2))^2 );
c = sqrt( (xy(1,1) - xy(1,3))^2 + (xy(2,1) - xy(2,3))^2 );

costeta1 = (( (c)^2 )-( (a)^2 )-( (b)^2) )/(-2*a*b);
teta1 = acosd(costeta1);

a = sqrt( (xy(1,4) - xy(1,3))^2 + (xy(2,4) - xy(2,3))^2 );
b = sqrt( (xy(1,3) - xy(1,2))^2 + (xy(2,3) - xy(2,2))^2 );
c = sqrt( (xy(1,2) - xy(1,4))^2 + (xy(2,2) - xy(2,4))^2 );

costeta2 = (( (c)^2 )-( (a)^2 )-( (b)^2) )/(-2*a*b);
teta2 = acosd(costeta2);

a = sqrt( (xy(1,1) - xy(1,4))^2 + (xy(2,1) - xy(2,4))^2 );
b = sqrt( (xy(1,4) - xy(1,3))^2 + (xy(2,4) - xy(2,3))^2 );
c = sqrt( (xy(1,3) - xy(1,1))^2 + (xy(2,3) - xy(2,1))^2 );

costeta3 = (( (c)^2 )-( (a)^2 )-( (b)^2) )/(-2*a*b);
teta3 = acosd(costeta3);

a = sqrt( (xy(1,1) - xy(1,4))^2 + (xy(2,1) - xy(2,4))^2 );
b = sqrt( (xy(1,2) - xy(1,1))^2 + (xy(2,2) - xy(2,1))^2 );
c = sqrt( (xy(1,2) - xy(1,4))^2 + (xy(2,2) - xy(2,4))^2 );

costeta4 = (( (c)^2 )-( (a)^2 )-( (b)^2) )/(-2*a*b);
teta4 = acosd(costeta4);

sum = teta1 + teta2 + teta3 + teta4;
if (sum < 360 )
    message = 'this is not a quderatial convex!';
    uiwait(msgbox(message,'Error','error'));
    close all
    error('this is not a quderatial convex!');
else
    message = 'input ok, press OK to continue';
    uiwait(msgbox(message,'','help'));
end

